package com.pzh.guli.service.edu.pojo;

import com.alipay.easysdk.factory.Factory;
import com.alipay.easysdk.kernel.Config;
import lombok.Data;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;

@Data
@Component
@ConfigurationProperties(prefix = "aliyun.pay")
@Slf4j
public class AliPayBean {
    private String appId; //ID
    private String appPrivateKey; //私玥
    private String appPublicKey; //公玥
    private String notifyUrl; //支付成功 回调地址 必须是公网IP

    @PostConstruct
    public void init(){
        //支付初始化
        Config option=getOptions();
        option.appId=this.appId;
        option.merchantPrivateKey=this.appPrivateKey;
        option.alipayPublicKey=this.appPublicKey;
        option.notifyUrl=this.notifyUrl;
        Factory.setOptions(option);
        log.info("支付宝bean初始化成功");
    }
    public Config getOptions(){
        Config config=new Config();
        config.protocol="https";
        config.gatewayHost="openapi.alipaydev.com"; //设置网关 支付宝默认
        config.signType="RSA2"; //加密方式
        return config;
    }
}
